#include "customtoolbutton.h"

CustomToolButton::CustomToolButton(QWidget *parent) : QToolButton(parent)
{   
    Menu = new QMenu;
    Menu->addAction(new QAction(parent));
    defaultmode = true;
    setMenu(Menu);

    setPopupMode(QToolButton::MenuButtonPopup);
    QObject::connect(this, SIGNAL(triggered(QAction*)),
                     this, SLOT(ChangeDefaultAction(QAction*)));
}

void CustomToolButton::addAction(QAction * Action)
{
    if (defaultmode)
    {
        Menu->clear();
        defaultmode = false;
    }
    Menu->addAction(Action);
}

void CustomToolButton::ChangeDefaultAction(QAction* action)
{
    setDefaultAction(action);
    setToolTip(ToolTip);
}
